package dynamicJsonVerifyer.demo.impl;

import com.alibaba.fastjson.JSONObject;
import dynamicJsonVerifyer.AppointTransformer;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component("iot.property")
public class PropertyAppointTransformer implements AppointTransformer {

    public Map<String, String> getIdentifier(JSONObject json) {
        Map<String, String> map = new HashMap<>();
        map.put("productKey", json.get("productKey").toString());
        return map;
    }

    public JSONObject transform(JSONObject json) {
        JSONObject result = new JSONObject();
        JSONObject items = json.getJSONObject("items");
        for(String key : items.keySet()){
            JSONObject value = items.getJSONObject(key);
            result.put(key, value.get("value"));
        }
        return json.getJSONObject("value");
    }
}
